<template>
  <div class="app-container">
    <div class="search-container">
      <el-form ref="queryParamsRef" :inline="true" :model="queryParams" label-width="110px">
        <el-form-item label="住院/门诊" prop="inoroutFlag">
          <el-radio-group v-model="queryParams.inoroutFlag" @change="handleQuery">
            <el-radio-button value="">全部</el-radio-button>
            <el-radio-button value="4">门诊</el-radio-button>
            <el-radio-button value="1">住院</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="开单时间" prop="">
          <el-date-picker v-model="dateRange" :shortcuts="$shortcuts()" :unlink-panels="true"
                          end-placeholder="结束日期" range-separator="-" start-placeholder="开始日期"
                          style="width: 100%" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss"
                          @change="handleQuery"></el-date-picker>
        </el-form-item>
        <el-form-item label="患者姓名" prop="name">
          <el-input
            v-model="queryParams.name"
            clearable
            placeholder="请输入患者姓名"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="住院号/门诊号" prop="hospitalNoOrClinicNo">
          <el-input
            v-model="queryParams.hospitalNoOrClinicNo"
            clearable
            placeholder="请输入住院号或者门诊号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="申请单号" prop="applyNo">
          <el-input
            v-model="queryParams.applyNo"
            clearable
            placeholder="请输入申请单号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="开单科室" prop="applyDept">
          <base-dept-tree
            :org-id="userInfo.orgId"
            :placeholder="'开单科室'"
            :value="queryParams.applyDept"
            class="width-120"
            @deptSelect="applyDeptSelect"
          />
        </el-form-item>
        <el-form-item label="患者所在病区" prop="wardCode">
          <el-input
            v-model="queryParams.wardCode"
            clearable
            placeholder="请输入患者所在病区"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="药品名称" prop="drugName">
          <el-input
            v-model="queryParams.drugName"
            clearable
            placeholder="请输入药品名称"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery"/>
        </el-form-item>
      </el-form>
    </div>
    <allergy-table ref="allergyTableRef" :date-range="dateRange" :query-params="queryParams"/>
  </div>
</template>
<script lang="ts" setup>
import {useUserStoreHook} from "@/store/modules/user.ts";
import AllergyTable from "@/views/infusion/allergyTestingConfirm/allergyTable.vue";

const useUserStore = useUserStoreHook();
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo

const {proxy} = getCurrentInstance() as any;
const date = proxy.$parseTime(new Date(), "{y}-{m}-{d} ");
const dateRange = ref([date + "00:00:00", date + "23:59:59"]);

const queryParamsRef = ref()
const allergyTableRef = ref()

const queryParams = ref({
  name: '',
  hospitalNoOrClinicNo: "",
  inoroutFlag: "",
  applyNo: "",
  applyDept: "",
  wardCode: "",
  drugName: "",
  operatePerson: "",
  confirmPerson: "",
  operateTime: "",
  orgId: userInfo.orgId,
  confirmTime: ""
})

/** 搜索按钮操作 */
function handleQuery() {
  nextTick(()=>{
    allergyTableRef.value.getList();
  })
}

/** 重置按钮操作 */
function resetQuery() {
  queryParamsRef.value.resetFields()
  // proxy.resetForm("queryRef");
  handleQuery();
}


function applyDeptSelect(node: any) {
  queryParams.value.applyDept = node.deptId;
  handleQuery()
}

onMounted(() =>{
  handleQuery();
})
</script>

<style scoped>

</style>
